/*
 * @Date: 2023-11-10 19:05:39
 * @LastEditors: zhaozhenguo zhaozhenguo@tuyoogame.com
 * @LastEditTime: 2023-12-29 10:50:54
 */
use crate::sim_model::SpadesMatchData;

#[derive(Debug)]
pub enum ScoreConditionEnum {
    /**
     * 分差在1-39
     */
    ScoreA = 1 << 0,
    /**
     * 分差在40-79
     */
    ScoreB = 1 << 1,
    /**
     * 分差在80+
     */
    ScoreC = 1 << 2,
    ScoreD = 1 << 3,
}

#[derive(Debug)]
pub enum ConditionEnum {
    ConditionA = 1 << 0,
    ConditionB = 1 << 1,
    ConditionC = 1 << 2,
    ConditionD = 1 << 3,
}

pub struct SimCondition {
    score_id: i32,
    condition: i32,
}

impl SimCondition {
    pub fn new(score_id: i32, condition: i32) -> Self {
        SimCondition {
            condition: condition,
            score_id: score_id,
        }
    }
    /**
     * 检查是否满足条件
     */
    pub fn is_met(&self, data: &SpadesMatchData) -> bool {
        if data.team_win_id == -1 {
            //平局不加入计算
            return false;
        }
        let delta = (data.team_scores[0] - data.team_scores[1]).abs() as i32;
        if delta >= self.score_id  && delta <self.score_id+5 {
            return true;
        }
        return false;
        // if self.score_id & ScoreConditionEnum::ScoreA as i32 == ScoreConditionEnum::ScoreA as i32 {
        //     let delta = (data.team_scores[0] - data.team_scores[1]).abs();
        //     if delta >= 1 && delta <= 39 {
        //         return true;
        //     }
        // }
        // if self.score_id & ScoreConditionEnum::ScoreB as i32 == ScoreConditionEnum::ScoreB as i32 {
        //     let delta = (data.team_scores[0] - data.team_scores[1]).abs();
        //     if delta >= 40 && delta <= 79 {
        //         return true;
        //     }
        // }
        // if self.score_id & ScoreConditionEnum::ScoreC as i32 == ScoreConditionEnum::ScoreC as i32 {
        //     let delta = (data.team_scores[0] - data.team_scores[1]).abs();
        //     if delta >= 80 {
        //         return true;
        //     }
        // }
    }
}
